<?php
/**
 * Created by PhpStorm.
 * User: ownfi
 * Date: 2017-04-13
 * Time: 20:28
 */

namespace App\Services\Impl;


use App\Common\Constant\Params;
use App\Events\MasterCashed;
use App\Events\MasterReturnFund;
use App\Models\MasterCash;
use App\Models\MasterFund;
use App\Models\MasterTradeLog;
use App\Models\MerchantTradeLog;
use App\Services\IFinanceService;
use App\Services\IMasterLogService;
use App\Services\IWalletService;
use App\Services\Request;
use DB;
use Log;

class FinanceServiceImpl implements IFinanceService
{
    private $walletService;
    private $masterLogService;

    /**
     * FinanceServiceImpl constructor.
     */
    public function __construct(IWalletService $walletService,IMasterLogService $masterLogService)
    {
        $this->walletService = $walletService;
        $this->masterLogService = $masterLogService;
    }

    public function masterFundHistory($master_id)
    {
        $model = MasterTradeLog::alias('t1')->select('t1.*')->orderBy('t1.add_time','DESC')
            ->where('master_id',$master_id)->where(function($query){
                $query->where(function($query){
                    $query->where('type',Params::TRADE_TYPE_ASSURE)->where('status',Params::TRADE_STATUS_SUCCESS);
                })->orWhere('type',Params::TRADE_TYPE_RETURN_ASSURE);
            })->with(['assoc']);
//        $model = MasterTradeLog::alias('t1')->select('t1.*')->orderBy('t1.add_time','DESC')
//            ->where('master_id',$master_id)
//            ->whereIn('type',[Params::TRADE_TYPE_ASSURE,Params::TRADE_TYPE_RETURN_ASSURE])->with(['assoc']);
        return $model->get();
    }

    public function masterWalletHistory($master_id)
    {
        $model = MasterTradeLog::alias('t1')->select('t1.*')->orderBy('t1.add_time','DESC')
            ->where('master_id',$master_id)
            ->whereIn('type',[Params::TRADE_TYPE_CASH,Params::TRADE_TYPE_ORDER])->with(['assoc']);
        return $model->paginate(config('common.perpage'));
    }


}